package com.leapp.sk.ui.adapter

import android.content.Context
import com.example.mvp.adapter.BaseLibAdapter
import com.example.mvp.adapter.BaseLibMultipleViewAdapter
import com.example.mvp.binder.BaseDataBinder
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.delegate.XDelegate
import com.leapp.sk.bean.EmojiconEntity
import com.leapp.sk.binder.adapter.join.SearchClassAdapterBinder
import com.leapp.sk.binder.im.SingleChatBinder
import com.leapp.sk.viewdelegate.adapter.im.EmojiconBigGridAdapterDelegate
import com.leapp.sk.viewdelegate.adapter.im.EmojiconGridAdapterDelegate

/**
 * 表情适配器
 * @author  chaohaipeng  on 2018/7/13.
 */
class EmojiconGridAdapter(context: Context, mlist: List<EmojiconEntity>, type: EmojiconEntity.Type?) : BaseLibMultipleViewAdapter<EmojiconEntity>(context, mlist) {
    /**
     * 表情类别
     */
    val mType = type
    /**
     * 表情数据
     */
    val mList = mlist
    /**
     * 上下文
     */
    val mContext = context

    override fun bindEvenListener(viewDelegate: BaseAdapterDelegate?, position: Int) {
    }

    override fun notifyView(viewDelegate: BaseAdapterDelegate?, position: Int) {
        if (mType == EmojiconEntity.Type.BIG_EXPRESSION){
            if(viewDelegate  is EmojiconBigGridAdapterDelegate) {
                val emojiconBigGridAdapterDelegate = viewDelegate
                emojiconBigGridAdapterDelegate.setData(mContext, mList.get(position))
            }
        }else{
            if(viewDelegate  is EmojiconGridAdapterDelegate){
                val emojiconGridAdapterDelegate = viewDelegate
                emojiconGridAdapterDelegate.setData(mContext, mList.get(position))
            }

        }


    }

    override fun getDelegate(position: Int): BaseAdapterDelegate? {
        var baseAdapterDelegate: BaseAdapterDelegate? = null
        if (mType == EmojiconEntity.Type.BIG_EXPRESSION) {
            try {
                baseAdapterDelegate = EmojiconBigGridAdapterDelegate::class.java!!.newInstance()
            } catch (e: InstantiationException) {
                e.printStackTrace()
            } catch (e: IllegalAccessException) {
                e.printStackTrace()
            }
        } else {
            try {
                baseAdapterDelegate = EmojiconGridAdapterDelegate::class.java!!.newInstance()
            } catch (e: InstantiationException) {
                e.printStackTrace()
            } catch (e: IllegalAccessException) {
                e.printStackTrace()
            }
        }

        return baseAdapterDelegate


    }

    override fun getDataBinder(position: Int): BaseDataBinder<*, *> {
        return SingleChatBinder()
    }

    override fun getItemData(position: Int): Any {
        return mList.get(position)
    }


}